REM Show notes menu
REM Title:      Director:Menus.IntNotes.Show
REM Author:     Philip Ludlam
REM Version:    0.31 Beta, Saturday the 3rd of November, 2001
REM Copyright:  (C) Philip Ludlam 2001

REM This program is free software; you can redistribute it and/or modify it
REM under the terms of the GNU General Public License as published by the Free
REM Software Foundation; either version 2 of the License, or (at your option)
REM any later version.
REM
REM This program is distributed in the hope that it will be useful, but WITHOUT
REM ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
REM FITNESS FOR APARTICULAR PURPOSE. See the GNU General Public License for more
REM details.
REM
REM You should have received a copy of the GNU General Public License along with
REM this program; if not, write to the Free Software Foundation, Inc., 59 Temple
REM Place - Suite 330, Boston, MA 02111-1307, USA

ON ERROR PROCerror
REM *SPOOL scsi::4.$.DATA
REM TRACE ON

DIM block% 1023,syntax% 255,output% 255,file_area% 2047
file_size%=0:file_ptr%=0:file_valid%=FALSE

Menu=FNswi_number("Director_Menu")
EndMenu=FNswi_number("Director_EndMenu")
Option=FNswi_number("Director_Option")
Command=FNswi_number("Director_Command")
Dash=FNswi_number("Director_Dash")

REM Get command line
SYS "OS_GetEnv" TO comm%
REM VDU4:PRINT FNstring(comm%)
SYS "OS_ReadArgs","name,quit,file",comm%,block%,1023

IF block%!8=0 THEN
  file$="Director:Menus.IntNotes.Notes.Notes"
ELSE
  file$=FNstring(block%!8)
  IF INSTR(file$,"$")=0 AND INSTR(file$,":")=0 file$="Director:Menus.IntNotes.Notes."+file$
ENDIF
file_valid%=FNfile_valid(file$,1)
IF file_valid% THEN
  PROCfile_load(file$)
ENDIF

SYS Menu,"Notes"

IF file_valid% THEN
  line$=FNfile_read:lineno%=1
  WHILE file_ptr%<=file_size%
    PROCprocess(line$)
    line$=FNfile_read:lineno%+=1
  ENDWHILE

  SYS Dash
ENDIF

SYS Option,"""New ..."" -len 256 -sub NotesNew"
SYS Command,"/Director:Menus.IntNotes.Modify -file """+file$+""" -add ""<MenuText>"""
SYS EndMenu

*Set Director$Menu Notes
PROCmenu_notesnew

REM *SPOOL
END

:

DEF PROCmenu_notesnew
SYS Menu,"""New "" NotesNew"
SYS Option," "" "" -len 256"
SYS Command,"/Director:Menus.IntNotes.Modify -file """+file$+""" -add ""<MenuText>"""
SYS EndMenu
ENDPROC

:

DEF PROCprocess(line$)
LOCAL col$:col$=""
SYS "OS_ReadArgs","/a,priority/k,sub/k,notes/k",line$,block%,1024
text$=FNstring(!block%)
IF block%!4<>0 pri$="-fg <Director$Notes$"+FNstring(block%!4)+">" ELSE pri$=""
IF block%!8<>0 sub$=FNstring(block%!8) ELSE sub$=""
IF block%!12<>0 notes$=FNstring(block%!12) ELSE notes$=""

SYS Option,""""+text$+""""+pri$+" -len 256 -sub ""Dynamic:/Director:Menus.IntNotes.Sub -file """""+file$+""""" -line "+STR$(lineno%)+""""
SYS Command,"/Director:Menus.IntNotes.Modify -file """+file$+""" -line "+STR$(lineno%)+" -edit ""<MenuText>"""
ENDPROC

:

DEF FNswi_number(n$)
SYS "OS_SWINumberFromString",,n$ TO a%
=a%

:

DEF FNstring(p%):LOCAL a$:a$=""
WHILE ?p%>31
  a$+=CHR$(?p%):p%+=1
  ENDWHILE:=a$

:

DEF FNstring_c(s%,l%):LOCAL a$,p%:a$="":p%=0
WHILE s%?p%>31 AND p%<=l%
  a$+=CHR$(s%?p%):p%+=1
  ENDWHILE:=a$

:

DEF PROCfile_load(file$)
LOCAL len%
SYS "OS_File",16,file$,file_area% TO ,,,,len%
file_area%?len%=0
file_size%=len%
ENDPROC

:

DEF FNfile_read
LOCAL i$:i$=""
WHILE i$="" AND file_ptr%<=file_size%
  i$=FNstring_c(file_area%+file_ptr%,file_size%-file_ptr%)
  file_ptr%+=LEN(i$)+1
  ENDWHILE
=i$

:

REM want% = to what object type you want to find/are looking for
DEF FNfile_valid(file$,want%):LOCAL ans%
SYS "XOS_File",17,file$ TO ans%
=(ans%=want%)

:

DEF PROCerror
ON ERROR OFF
VDU 4
PRINT "Error in: !Director.Menus.IntNotes.Show"
PRINT "Report:   ";REPORT$
PRINT "Line:     ";ERL
REM *SPOOL
END

:
